package entity;

import abstractEntity.ModelAbstract;

public class Model extends ModelAbstract  
{
	String name;
	String[] dataDesctiption;
	
	//Constructor: set data array to default(empty);
	public Model()
	{
		dataDesctiption= new String[32];
		for(int i=0; i<dataDesctiption.length;i++)
			dataDesctiption[i]="";
	}
	
	//Constructor:set name of Firmware version, set data array to default(empty);
	public Model(String name)
	{
		this.name=name;
		dataDesctiption= new String[32];
		for(int i=0; i<dataDesctiption.length;i++)
			dataDesctiption[i]="";
	}

	@Override
	//set name of Firmware version, set data array, return model
	public Model model(String name, String[] descriptions) 
	{
		this.name=name;
		addErrorData(descriptions);
		return this;
		
	}

	@Override
	//set version of firmware(name)
	public void name(String name) 
	{
		this.name=name;
	}

	@Override
	//return error description by errorID number if exist, else return null
	public String getDescriptionByErrorID(int errorID) 
	{
		if(errorID<dataDesctiption.length)
			return dataDesctiption[errorID];
		else
			return null;
	}

	@Override
	//add error data in array by error number. check if error number not large of 32
	public boolean addErrorData(int errorNum, String description) 
	{
		if(errorNum<dataDesctiption.length && !description.equals(null))
		{
			dataDesctiption[errorNum]=description;
			return true;
		}
		return false;
	}

	@Override
	//get version of firmware(name)
	public String name() 
	{
		return name;
	}

	@Override
	public boolean addErrorData(String[] descriptions) 
	{
		try
		{
			for(int i=0; i<dataDesctiption.length;i++)
			{
				if(descriptions.length<i)
				{
					dataDesctiption[i]="Reserved";
					continue;
				}
				else if(descriptions[i]=="")
				{
					dataDesctiption[i]="Reserved";
					continue;
				}
				else
				{
					dataDesctiption[i]=descriptions[i];
				}
				
				
			}
		}
		catch (Exception e) 
		{
			System.err.println("error on insert data");
			return false;
		}
		return true;
	}

	
	
	

}
